package com.qbccn.usercenter.controller;

import com.qbccn.usercenter.service.SystemService;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author linke
 * @date 2020/5/24 21:57
 * @description
 */
@Controller
public class IndexController {

  @Autowired
  private HttpServletRequest request;
  @Autowired
  private SystemService systemService;

  @PreAuthorize("authenticated")//需要登录后才能访问
  @GetMapping("")
  public String index() {
    return "index";
  }

  @PreAuthorize("authenticated")//需要登录后才能访问
  @GetMapping("/welcome")
  public String welcome() {
    return "welcome";
  }

  @PreAuthorize("hasAnyRole('user','admin')")//需要用户角色
  @GetMapping("userFind")
  public String userFind() {
    request.setAttribute("systemList", systemService.getAll());
    return "user-find";
  }

  @PreAuthorize("hasAnyRole('user','admin')")//需要用户角色
  @GetMapping("orderFind")
  public String orderFind() {
    request.setAttribute("systemList", systemService.getAll());
    return "order-find";
  }
}
